package com.ustc.hewei.nettyrpc2_0.common.hook;

import com.ustc.hewei.nettyrpc2_0.common.factory.ThreadPoolFactory;
import lombok.extern.slf4j.Slf4j;

/**
* @description: 关闭时释放资源的钩子
* @author hewei
* @date 2022/9/26 19:49
* @version 1.0
*/

@Slf4j
public class ShutdownHook {

    private ShutdownHook() {}
    private static ShutdownHook shutdownHook = new ShutdownHook();

    public static ShutdownHook getShutdownHook() {
        return shutdownHook;
    }

    public void addShutdownHook() {
        log.info("添加JVM关闭时的钩子...");
        Runtime.getRuntime().addShutdownHook(new Thread(ThreadPoolFactory::shutDownAll));
    }

}
